# -*- codeing = utf-8 -*-
# @Time : 2022/11/8 10:44
# @Author : 小马
# @File: app.py
# @Software : PyCharm
import GetData
from flask import Flask,render_template
from flask import request
import sqlite3
import Methods
import json
import Service

app=Flask(__name__)
@app.route('/',methods=['GET','POST'])
def login():
    data=request.get_data()
    if(len(data)>0):
      print(data)
      phonenumber = request.form.get('phonenumber')
      password = request.form.get('password')
      p = '"' + phonenumber + '"'
      password1=Methods.SelectFromTable(p)
      if(password==password1 or password is password1):
          return render_template("index.html")
      else:
          print(password)
          print(password1)

    return render_template("login.html")
@app.route('/forgotpassword')
def forgot():
    return render_template("forgot-password.html")
@app.route('/index')
def index():
    return render_template("index.html")

@app.route('/utilities-animation')
def animation():
    result=GetData.getDatafromDB()
    sql = "select sum(sewagetreatment) from sewage where year=2019"
    sql1 = "select sum(sewagetreatment) from sewage where year=2020"
    sql2="select sum(sewagetreatment) from sewage where year=2021"
    r = GetData.getDatafrom(sql)
    q = GetData.getDatafrom(sql1)
    l = GetData.getDatafrom(sql2)
    return render_template("utilities-animation.html",data=result,d1=int(r[0][0])/1000,d2=int(q[0][0])/1000,d3=int(l[0][0])/1000)

@app.route('/question')
def question():
    r = Service.ReadAndAnalysisQuestion()
    return render_template("question.html",data=r)
@app.route('/buttons')
def buttons():
    d=Methods.searchall()






    return render_template("buttons.html",waterlist=d)
@app.route('/charts')
def charts():
    d=Service.ReadAndAnalysisExcel()
    return render_template("charts.html",dateList=d)
@app.route('/export')
def export():
    Methods.exportTo()
    d = Methods.searchall()
    return render_template("buttons.html",waterlist=d)


@app.route('/tables')
def tables():
    return render_template("tables.html")
@app.route('/cards')
def cards():
    a=Methods.searchMachine()
    b=Methods.searchSumSix()
    b1 = int(b[0][0])
    b2 = int(b[0][1])
    b3 = int(b[0][2])
    b4 = int(b[0][3])
    b5 = int(b[0][4])
    b6 = int(b[0][5])
    d=Methods.searchDateAndWater()
    Xdata=d[0]
    Ydata=d[1]
    return render_template("cards.html",Xdata=Xdata,Ydata=Ydata,m1=a[0],m2=a[1],m3=a[2],m4=a[3],m5=a[4],m6=a[5],n1=b1,n2=b2,n3=b3,n4=b4,n5=b5,n6=b6)

@app.route('/register',methods=['GET','POST'])
def register():
    data = request.get_data()
    print("----------")
    print(data)
    if(len(data)>0):
        phonenumber=request.form.get('phonenumber')
        password=request.form.get('password')
        email=request.form.get('email')
        if(len(phonenumber)>0 and len(password)>0):
            p='"'+phonenumber+'"'
            pa='"'+password+'"'
            e='"'+email+'"'
            Methods.InsertIntoTable(p,pa,e)
            return render_template("login.html")
    return render_template("register.html")


if __name__=='__main__':
    app.run(debug=True)